﻿using Rhino;
using Rhino.Commands;
using Rhino.DocObjects;
using Rhino.Geometry;
using Rhino.Input;
using Rhino.Input.Custom;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;

namespace YangTools.Realization
{
    class SelObjectsByMaterial
    {
        public void Select()
        {
            var o = RhinoHelper.Selection.GetObjects("选择一个使用需求材质的物体：", ObjectType.AnyObject, 1, -1);
            if (o.Count == 0) return;
            var ma = o[0].GetMaterial(true);
            var m = ma.Name;

            foreach (var obj in RhinoDoc.ActiveDoc.Objects)
            {
                var i = obj.GetMaterial(true);
                if (i.Name == m) obj.Select(true);
            }

            RhinoDoc.ActiveDoc.Views.Redraw();
        }
    }
}
